%
% Simulator for 60 Hz filtering effect.
%

%
% Parameters
%

% segment length
N=1024;
% percentage of left out signal before reaching steady state
Burn_in=.1;
Nt=(1+Burn_in)*N;
% signal to noise ratio
SNR=20;
%
% Half the sampling frequency
fs2=125
%
% Model simulation
p_o=2
w=randn(2,Nt+p_o);
x=zeros(1,Nt+p_o);
y=x;
for k=1+p_o:Nt+p_o
x(k)=2*cos(2*pi*7.5/fs2)*.85*x(k-1)-.85^2*x(k-2)+w(1,k);
y(k)=.5*y(k-1)+w(2,k);
end
u=[x;y];
u=u(:,Burn_in*N+p_o+1:Nt+p_o);
%
su=std(u');    
%
% Inference 60 Hz
%
v=cos((0:N-1)*2*pi*60/(2*fs2));
sv=std(v);
%
snr_factor=(su(2)/sv)*10^(-SNR/20);
%
ut=u+ones(2,1)*v*snr_factor;
%
dem=[1.0000   -0.1253    0.9956];
num=[0.9978   -0.1253    0.9978];
freqz(num,dem,512);
%
uf=filter(num,dem,ut);
%



